let base = 'http://192.168.3.92:8085'
let app = getApp()
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const requestData = (params) => {
  return new Promise((resolve, reject) => {
    if (typeof params === 'object') {
      if (params.url.toLocaleLowerCase === 'get') {
        params.url = 'GET'
      }
      if (params.url.toLocaleLowerCase === 'post') {
        params.url = 'POST'
      }
      let requestTask = wx.request({
        url: base + params.url,
        data: params.data,
        header: params.header ||{'content-type':'application/x-www-form-urlencoded'},
        dataType: params.dataType,
        method: params.method || 'GET',
        responseType: params.responseType || 'text',
        success: function (res) {
          resolve (res.data)
        }
      })
      if (params.abort) {
        requestTask.abort() 
      }
    } else {
      reject('sdsa')
    }
  })
}
const pureClick = (url) => {
 if (app.globaData.isClicked) {
   return
 }
 wx.navigateTo({
   url: `${url}`
 })
}
module.exports = {
  formatTime: formatTime,
  requestData: requestData
}
